"""
__author__ = 'berlinyoung'
@File   :add_member_page.py
@Date   :2021/9/4 12:48
-*- coding: utf-8 -*-

1.实现页面细节
2.优化测试用例
3.封装basepage
"""
from time import sleep
from selenium.webdriver.common.by import By
from test_web.training_step3.po.base_page import BasePage


class AddMemberPage(BasePage):
    # 添加baseurl,可以支持测试用例灵活配置起始页
    # basepage 完全和业务逻辑解耦
    _base_url = ""
    #将变量分离出来，方便以后修改元素时只需要修改一个位置一遍即可
    _username_ele = (By.CSS_SELECTOR,"#username")
    _member_alias_ele = (By.CSS_SELECTOR, "#memberAdd_acctid")
    _telephone_ele = (By.CSS_SELECTOR, "#memberAdd_phone")
    _save_button = (By.CSS_SELECTOR, ".js_btn_save")
    _cancel_button = (By.CSS_SELECTOR, ".js_btn_cancel")

    def add_member(self,name):
        """
        添加成员操作
        :return: 返回通讯录页面的实例化对象
        """
        # 输入姓名，ID，手机号码
        # 解包元组，传入两个参数
        # 如果不解包元组，传入为(By.CSS_SELECTOR,"#username")，解包则传入By.CSS_SELECTOR,"#username"
        self.driver.implicitly_wait(3)
        self.find(self._username_ele).send_keys(name)
        self.find(*self._member_alias_ele).send_keys("110")
        self.find(*self._telephone_ele).send_keys("16816881688")
        self.find(*self._save_button).click()

        # 导入操作复制在方法内部，解决循环导入的问题
        from test_web.training_step3.po.contact_page import ContactPage
        return ContactPage(self.driver)

    def add_member_fail(self,name):
        # 输入姓名，ID，手机号码
        # 解包元组，传入两个参数
        # 如果不解包元组，传入为(By.CSS_SELECTOR,"#username")，解包则传入By.CSS_SELECTOR,"#username"
        self.driver.implicitly_wait(3)
        self.find(self._username_ele).send_keys(name)
        self.find(*self._member_alias_ele).send_keys("222000")
        self.find(*self._telephone_ele).send_keys("16816881688")
        self.find(*self._save_button).click()
        self.find(*self._cancel_button).click()

        # 导入操作复制在方法内部，解决循环导入的问题
        from test_web.training_step3.po.contact_page import ContactPage
        return ContactPage(self.driver)